﻿namespace Common.Core.Encrypt
{
    /// <summary>
    /// RSA原始密钥对
    /// </summary>
    public class RsaKey
    {
        public RsaKey()
        {
        }
        public RsaKey(string publicKey, string privateKey)
        {
            PublicKey = publicKey;
            PrivateKey = privateKey;
        }

        /// <summary>
        /// 公钥
        /// </summary>
        public string PublicKey { get; protected internal set; }

        /// <summary>
        /// 私钥
        /// </summary>
        public string PrivateKey { get; protected internal set; }

        public string ToPkcsPublicKey()
        {
            return PublicKey
                    .Replace("-----BEGIN PUBLIC KEY-----", "")
                    .Replace("-----END PUBLIC KEY-----", "")
                    .Replace("\n", "");
        }
        public string ToPkcsPrivateKey()
        {
            return PrivateKey
                .Replace("-----BEGIN RSA PRIVATE KEY-----", "")
                .Replace("-----END RSA PRIVATE KEY-----", "")
                .Replace("-----BEGIN PRIVATE KEY-----", "")
                .Replace("-----END PRIVATE KEY-----", "")
                .Replace("\n", "");
        }
    }

}